package _11_位运算;

public class _201_数字范围按位与 {

    public static void main(String[] args) {

        _201_数字范围按位与 v = new _201_数字范围按位与();
        System.out.println(v.rangeBitwiseAnd(10, 12));

    }

    // 两位查找相同的公共前缀，找到后
    public int rangeBitwiseAnd(int left, int right) {
        int shift = 0;
        // 找到公共前缀
        while (left < right) {
            left >>= 1;
            right >>= 1;
            ++shift;
        }
        return left << shift;
    }

}
